<?php
namespace app\controller;

use app\BaseController;
use app\services\FormService;
use think\facade\View;

class Index extends BaseController
{
    public function index()
    {
        return View::fetch('/form');
    }

    public function form(){
        if ($this->request->isPost()) {
            // 获取前端提交的数据
            $RT = $this->request->post('RT');
            $Area = $this->request->post('Area');
            $Height = $this->request->post('Height');

            // 计算总和
            $total = array_sum($Area);

            // 计算每行数据在总数中的占比
            $percentages = array_map(function($value) use ($total) {
                return round($value / $total * 100,2);
            }, $Area);
            $data=[
                'RT'=>$RT,
                'Area'=>$Area,
                'Height'=>$Height,
                'Total'=>$total,
                'Area2'=>$percentages,
            ];

            return View::assign('/pdf',$data);
        }
        return '非法提交';
    }
}
